﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.Live.ServerControls.VE.Constants;

[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.SetMapStyle.js", "text/javascript")]
[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.SetMapStyle.debug.js", "text/javascript")]

namespace Microsoft.Live.ServerControls.VE.Extenders
{
    [ToolboxData(@"<{0}:SetMapStyle ID=""SetMapStyleExtender1"" runat=""server"" MapStyle=""Road"" MapControlID="""" TargetControlID="""" ></{0}:SetMapStyle>")]
    public sealed class SetMapStyle : ExtenderBase
    {

        #region Properties

        /// <summary>
        /// A VEMapStyle Enumeration value specifying the map style
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [DefaultValue(MapStyle.Road)]
        [Description("A VEMapStyle Enumeration value specifying the map style")]
        public MapStyle MapStyle 
        {
            get
            {
                if (ViewState[SetMapStyleExtenderControlProperty.MapStyle] != null)
                {
                    return (MapStyle)ViewState[SetMapStyleExtenderControlProperty.MapStyle];
                }
                else
                {
                    return MapStyle.Road;
                }
            }
            set { ViewState[SetMapStyleExtenderControlProperty.MapStyle] = value; } 
        }

        #endregion

        #region ExtenderControl Members

        protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(Control targetControl)
        {
            ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor("Microsoft.Live.ClientControls.VE.Extenders.SetMapStyle", targetControl.ClientID);
            descriptor.AddProperty(SetMapStyleExtenderControlProperty.MapStyle, MapStyle.ToVEEnum());
            descriptor.AddProperty(ExtenderControlProperty.MapControlID, MapControlID);
            yield return descriptor;
        }

        protected override IEnumerable<ScriptReference> GetScriptReferences()
        {
            List<ScriptReference> descriptors = new List<ScriptReference>();
            descriptors.Add(new ScriptReference("Microsoft.Live.ServerControls.VE.Extenders.SetMapStyle.js", GetType().Assembly.FullName));
            return descriptors;
        }

        #endregion
    }
}
